﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using UtilZ.Dotnet.Ex.Base;
using UtilZ.Dotnet.Ex.Log;
using UtilZ.Dotnet.WindowsDesktopEx.WPF;

namespace WpfApp.Test
{
    /// <summary>
    /// TestNotifyManager.xaml 的交互逻辑
    /// </summary>
    public partial class TestNotifyManager : Window
    {
        public TestNotifyManager()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            var redirectAppenderToUI = (RedirectAppender)Loger.GetAppenderByName(null, "RedirectToUI");
            if (redirectAppenderToUI != null)
            {
                redirectAppenderToUI.RedirectOuput += RedirectLogOutput;
            }
        }

        private void RedirectLogOutput(object sender, RedirectOuputArgs e)
        {
            try
            {
                logControl.AddLog(string.Format("{0} {1}", DateTime.Now, e.Item.Content), e.Item.Level);
            }
            catch (Exception ex)
            {
                logControl.AddLog(ex.Message, LogLevel.Error);
            }
        }

        private void btnClearLog_Click(object sender, RoutedEventArgs e)
        {
            logControl.Clear();
        }


        private int _index = 1;
        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            int index = this._index++;
            NotifyManager.Default.Notify(new NotifyItem()
            {
                Text = $"{index} 这是OK信息,啦啦啦.",
                BackgroundColor = Brushes.Gray,
                MesageImage = NotifyManager.OKImg
            });
        }

        private void btnInfo_Click(object sender, RoutedEventArgs e)
        {
            int index = this._index++;
            NotifyManager.Default.Notify(new NotifyItem()
            {
                Text = $"{index} 这是info信息,啦啦啦.",
                BackgroundColor = Brushes.Green,
                MesageImage = NotifyManager.InfoImg,
                //Duration = 20000,
                Tag = new Person(TimeEx.GetTimestamp(), "这真的是info信息"),
                MouseClick = this.InfoMouseClick,
                Size = new System.Drawing.Size(400, 50),
            });
        }
        private void InfoMouseClick(NotifyItem item)
        {
            MessageBox.Show(((Person)item.Tag).Name);
        }

        private void btnWarn_Click(object sender, RoutedEventArgs e)
        {
            int index = this._index++;
            NotifyManager.Default.Notify(new NotifyItem()
            {
                Text = $"{index} 这是Warn信息,啦啦啦.",
                BackgroundColor = Brushes.Goldenrod,
                MesageImage = NotifyManager.WarnImg
            });
        }

        private void btnError_Click(object sender, RoutedEventArgs e)
        {
            int index = this._index++;
            NotifyManager.Default.Notify(new NotifyItem()
            {
                Text = $"{index} 这是Error信息,啦啦啦.",
                BackgroundColor = Brushes.Brown,
                MesageImage = NotifyManager.ErrorImg
            });
        }

        private void btnRing_Click(object sender, RoutedEventArgs e)
        {
            int index = this._index++;
            NotifyManager.Default.Notify(new NotifyItem()
            {
                Text = $"{index} 这是Ring信息,啦啦啦.",
                BackgroundColor = Brushes.HotPink,
                MesageImage = NotifyManager.RingImg
            });
        }




    }
}
